class Index {
    constructor() {
        //京东倒计时
        this.countDown();
        //轮播图
        this.nextImg();
        this.checkLogin();
    }
    nextImg() {
        let leftArr = document.querySelector('.arrow-l');
        let rightArr = document.querySelector('.arrow-r');
        let img = document.querySelectorAll('.t-img li')
        // console.log(img);
        // console.log(leftArr, rightArr);
        let k = img.length
        let i = 0;
        //左箭头
        leftArr.addEventListener('click', function () {
            i--;
            if (i < 0) i = k - 1;
            //循环清空
            img.forEach(function (val, ind) {
                img[ind].className = '';
            })
            img[i].className = 'next';
        })
        //右箭头
        rightArr.addEventListener('click', function () {
            i++;
            if (i > k - 1) {
                i = 0;
            }
            //循环清空
            img.forEach(function (val, ind) {
                img[ind].className = '';
            })
            img[i].className = 'next';
        });
        //定时器切换图片
        let times = setInterval(function fn() {
            i++;
            if (i > k - 1) {
                i = 0;
            }
            //循环清空
            img.forEach(function (val, ind) {
                img[ind].className = '';
            })
            img[i].className = 'next';
            //鼠标移入停止计时器移除开启定时器
            // this.$('.grid-col2-t').
            img[i].onmouseover = function () {
                clearInterval(times)
            }
            img[i].onmouseout = function () {
                times = setInterval(fn, 1500)
            }

        }, 1600);
    }
    //changeimg切换图片动画
    // changeimg(img) {
    //     //循环清空
    //     img.forEach(function (val, ind) {
    //         img[ind].className = '';
    //         img[ind].style.opacity = 1;
    //     })
    //     img[i].className = 'next';
    //     //切换图片动画
    //     img[i].style.opacity = 0;
    //     img[i].style.transition = '1.5s';
    // }
    countDown() {
        setInterval(function () {
            var dat = new Date();
            var hours = dat.getHours();
            var min = dat.getMinutes();
            var sec = dat.getSeconds();
            var dat1 = new Date();
            var cont;
            hours % 2 == 0 ? cont = hours : cont = hours - 1;
            dat1.setHours(cont + 2);
            dat1.setMinutes(0);
            dat1.setSeconds(0);
            var newdate = dat1 - dat;
            //获取总秒数
            var allsec1 = parseInt(newdate / 1000);
            //获取秒数
            var sec1 = parseInt(allsec1 % 60);
            //获取小时
            var hours1 = parseInt(allsec1 / (60 * 60))
            //获取分钟
            var min1 = parseInt((allsec1 % (60 * 60) - sec) / 60);
            // console.log(hours1, min1, sec1);
            Index.$('.hd_countdown strong').innerHTML = cont;
            Index.$('.timer .hour').innerHTML = hours1;
            Index.$('.timer .minute').innerHTML = min1;
            Index.$('.timer .second').innerHTML = sec1;
        }, 1000)
        //获取节点的方法
    }
    //验证是否登录
    checkLogin() {
        const TOKEN = localStorage.getItem('token');
        console.log(TOKEN);
        let userName = localStorage.getItem('userName')
        console.log(userName);
        let Name = document.querySelector('.fr li');
        let Namedown = document.querySelector('.login-t');
        let log = document.querySelector('.log');
        console.log(Name);
        if (TOKEN) {
            Name.firstElementChild.innerHTML = userName;
            Namedown.firstElementChild.innerHTML = userName;
            log.style.display = 'none'
        }
    }
    //获取节点的方法
    static $(ele) {
        let res = document.querySelectorAll(ele);
        return res.length == 1 ? res[0] : res;
    }
}
new Index();